home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / sys / test.c < prev   
Encoding:
C/C++ Source or Header  |  2002-04-18  |  8.9 KB  |  268 lines

  1. /* sys/test.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <config.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <gsl/gsl_math.h>
  24. #include <gsl/gsl_test.h>
  25.  
  26. #include <gsl/gsl_ieee_utils.h>
  27.  
  28. int
  29. main (void)
  30. {
  31.   double y, y_expected;
  32.  
  33.   gsl_ieee_env_setup ();
  34.  
  35.   /* Test for expm1 */
  36.  
  37.   y = gsl_expm1 (0.0); y_expected = 0.0;
  38.   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(0.0)");
  39.  
  40.   y = gsl_expm1 (1e-10); y_expected = 1.000000000050000000002e-10;
  41.   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(1e-10)");
  42.  
  43.   y = gsl_expm1 (-1e-10); y_expected = -9.999999999500000000017e-11;
  44.   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-1e-10)");
  45.  
  46.   y = gsl_expm1 (0.1); y_expected = 0.1051709180756476248117078264902;
  47.   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(0.1)");
  48.  
  49.   y = gsl_expm1 (-0.1); y_expected = -0.09516258196404042683575094055356;
  50.   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-0.1)");
  51.  
  52.   y = gsl_expm1 (10.0); y_expected = 22025.465794806716516957900645284;
  53.   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(10.0)");
  54.  
  55.   y = gsl_expm1 (-10.0); y_expected = -0.99995460007023751514846440848444;
  56.   gsl_test_rel (y, y_expected, 1e-15, "gsl_expm1(-10.0)");
  57.    
  58.   /* Test for log1p */
  59.  
  60.   y = gsl_log1p (0.0); y_expected = 0.0;
  61.   gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(0.0)");
  62.  
  63.   y = gsl_log1p (1e-10); y_expected = 9.9999999995000000000333333333308e-11;
  64.   gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(1e-10)");
  65.  
  66.   y = gsl_log1p (0.1); y_expected = 0.095310179804324860043952123280765;
  67.   gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(0.1)");
  68.  
  69.   y = gsl_log1p (10.0); y_expected = 2.3978952727983705440619435779651;
  70.   gsl_test_rel (y, y_expected, 1e-15, "gsl_log1p(10.0)");
  71.  
  72.   /* Test for gsl_hypot */
  73.  
  74.   y = gsl_hypot (0.0, 0.0) ; y_expected = 0.0;
  75.   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(0.0, 0.0)");
  76.  
  77.   y = gsl_hypot (1e-10, 1e-10) ; y_expected = 1.414213562373095048801688e-10;
  78.   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-10, 1e-10)");
  79.  
  80.   y = gsl_hypot (1e-38, 1e-38) ; y_expected = 1.414213562373095048801688e-38;
  81.   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-38, 1e-38)");
  82.  
  83.   y = gsl_hypot (1e-10, -1.0) ; y_expected = 1.000000000000000000005;
  84.   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e-10, -1)");
  85.  
  86.   y = gsl_hypot (-1.0, 1e-10) ; y_expected = 1.000000000000000000005;
  87.   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(-1, 1e-10)");
  88.  
  89.   y = gsl_hypot (1e307, 1e301) ; y_expected = 1.000000000000499999999999e307;
  90.   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e307, 1e301)");
  91.  
  92.   y = gsl_hypot (1e301, 1e307) ; y_expected = 1.000000000000499999999999e307;
  93.   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e301, 1e307)");
  94.  
  95.   y = gsl_hypot (1e307, 1e307) ; y_expected = 1.414213562373095048801688e307;
  96.   gsl_test_rel (y, y_expected, 1e-15, "gsl_hypot(1e307, 1e307)");
  97.  
  98.  
  99.   /* Test for acosh */
  100.  
  101.   y = gsl_acosh (1.0); y_expected = 0.0;
  102.   gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1.0)");
  103.  
  104.   y = gsl_acosh (1.1); y_expected = 4.435682543851151891329110663525e-1;
  105.   gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1.1)");
  106.  
  107.   y = gsl_acosh (10.0); y_expected = 2.9932228461263808979126677137742e0;
  108.   gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(10.0)");
  109.  
  110.   y = gsl_acosh (1e10); y_expected = 2.3718998110500402149594646668302e1;
  111.   gsl_test_rel (y, y_expected, 1e-15, "gsl_acosh(1e10)");
  112.  
  113.   /* Test for asinh */
  114.  
  115.   y = gsl_asinh (0.0); y_expected = 0.0;
  116.   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(0.0)");
  117.  
  118.   y = gsl_asinh (1e-10); y_expected = 9.9999999999999999999833333333346e-11;
  119.   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e-10)");
  120.  
  121.   y = gsl_asinh (-1e-10); y_expected = -9.9999999999999999999833333333346e-11;
  122.   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e-10)");
  123.  
  124.   y = gsl_asinh (0.1); y_expected = 9.983407889920756332730312470477e-2;
  125.   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(0.1)");
  126.  
  127.   y = gsl_asinh (-0.1); y_expected = -9.983407889920756332730312470477e-2;
  128.   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-0.1)");
  129.  
  130.   y = gsl_asinh (1.0); y_expected = 8.8137358701954302523260932497979e-1;
  131.   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1.0)");
  132.  
  133.   y = gsl_asinh (-1.0); y_expected = -8.8137358701954302523260932497979e-1;
  134.   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-1.0)");
  135.  
  136.   y = gsl_asinh (10.0); y_expected = 2.9982229502979697388465955375965e0;
  137.   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(10)");
  138.  
  139.   y = gsl_asinh (-10.0); y_expected = -2.9982229502979697388465955375965e0;
  140.   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-10)");
  141.  
  142.   y = gsl_asinh (1e10); y_expected = 2.3718998110500402149599646668302e1;
  143.   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(1e10)");
  144.  
  145.   y = gsl_asinh (-1e10); y_expected = -2.3718998110500402149599646668302e1;
  146.   gsl_test_rel (y, y_expected, 1e-15, "gsl_asinh(-1e10)");
  147.  
  148.   /* Test for atanh */
  149.  
  150.   y = gsl_atanh (0.0); y_expected = 0.0;
  151.   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.0)");
  152.  
  153.   y = gsl_atanh (1e-20); y_expected = 1e-20;
  154.   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(1e-20)");
  155.  
  156.   y = gsl_atanh (-1e-20); y_expected = -1e-20;
  157.   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(-1e-20)");
  158.  
  159.   y = gsl_atanh (0.1); y_expected = 1.0033534773107558063572655206004e-1;
  160.   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.1)");
  161.  
  162.   y = gsl_atanh (-0.1); y_expected = -1.0033534773107558063572655206004e-1;
  163.   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(-0.1)");
  164.  
  165.   y = gsl_atanh (0.9); y_expected = 1.4722194895832202300045137159439e0;
  166.   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.9)");
  167.  
  168.   y = gsl_atanh (-0.9); y_expected = -1.4722194895832202300045137159439e0;
  169.   gsl_test_rel (y, y_expected, 1e-15, "gsl_atanh(0.9)");
  170.  
  171.   /* Test for pow_int */
  172.  
  173.   y = gsl_pow_2 (-3.14); y_expected = pow(-3.14, 2.0);
  174.   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_2(-3.14)");
  175.  
  176.   y = gsl_pow_3 (-3.14); y_expected = pow(-3.14, 3.0);
  177.   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_3(-3.14)");
  178.  
  179.   y = gsl_pow_4 (-3.14); y_expected = pow(-3.14, 4.0);
  180.   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_4(-3.14)");
  181.  
  182.   y = gsl_pow_5 (-3.14); y_expected = pow(-3.14, 5.0);
  183.   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_5(-3.14)");
  184.  
  185.   y = gsl_pow_6 (-3.14); y_expected = pow(-3.14, 6.0);
  186.   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_6(-3.14)");
  187.  
  188.   y = gsl_pow_7 (-3.14); y_expected = pow(-3.14, 7.0);
  189.   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_7(-3.14)");
  190.  
  191.   y = gsl_pow_8 (-3.14); y_expected = pow(-3.14, 8.0);
  192.   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_8(-3.14)");
  193.  
  194.   y = gsl_pow_9 (-3.14); y_expected = pow(-3.14, 9.0);
  195.   gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_9(-3.14)");
  196.  
  197.   { 
  198.     int n;
  199.     for (n = -9; n < 10; n++) {
  200.       y = gsl_pow_int (-3.14, n); y_expected = pow(-3.14, n);
  201.       gsl_test_rel (y, y_expected, 1e-15, "gsl_pow_n(-3.14,%d)", n);
  202.     }
  203.   }
  204.  
  205. #ifdef HAVE_IEEE_COMPARISONS
  206.   /* Test for isinf, isnan, finite*/
  207.  
  208.   {
  209.     double zero, one, inf, nan;
  210.     int s;
  211.  
  212.     zero = 0.0;
  213.     one = 1.0;
  214.     inf = exp(1.0e10);
  215.     nan = inf / inf;
  216.     
  217.     s = gsl_isinf(zero);
  218.     gsl_test_int (s, 0, "gsl_isinf(0)");
  219.     
  220.     s = gsl_isinf(one);
  221.     gsl_test_int (s, 0, "gsl_isinf(1)");
  222.     
  223.     s = gsl_isinf(inf);
  224.     gsl_test_int (s, 1, "gsl_isinf(inf)");
  225.  
  226.     s = gsl_isinf(-inf);
  227.     gsl_test_int (s, -1, "gsl_isinf(-inf)");
  228.     
  229.     s = gsl_isinf(nan);
  230.     gsl_test_int (s, 0, "gsl_isinf(nan)");
  231.  
  232.  
  233.     s = gsl_isnan(zero);
  234.     gsl_test_int (s, 0, "gsl_isnan(0)");
  235.     
  236.     s = gsl_isnan(one);
  237.     gsl_test_int (s, 0, "gsl_isnan(1)");
  238.     
  239.     s = gsl_isnan(inf);
  240.     gsl_test_int (s, 0, "gsl_isnan(inf)");
  241.     
  242.     s = gsl_isnan(nan);
  243.     gsl_test_int (s, 1, "gsl_isnan(nan)");
  244.  
  245.  
  246.     s = gsl_finite(zero);
  247.     gsl_test_int (s, 1, "gsl_finite(0)");
  248.     
  249.     s = gsl_finite(one);
  250.     gsl_test_int (s, 1, "gsl_finite(1)");
  251.     
  252.     s = gsl_finite(inf);
  253.     gsl_test_int (s, 0, "gsl_finite(inf)");
  254.     
  255.     s = gsl_finite(nan);
  256.     gsl_test_int (s, 0, "gsl_finite(nan)");
  257.   }
  258. #endif
  259.  
  260.  
  261.   {
  262.     double x = gsl_fdiv (2.0, 3.0);
  263.     gsl_test_rel (x, 2.0/3.0, 4*GSL_DBL_EPSILON, "gsl_fdiv(2,3)");
  264.   }
  265.  
  266.   exit (gsl_test_summary ());
  267. }
  268.